﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Core;
using System.Linq.Expressions;

namespace IronCommander
{
    public static class CaliburnExtensionMethods
    {
        public static void SetValue<T>(this PropertyChangedBase obj, ref T field, T value, Expression<Func<T>> notify, params Expression<Func<object>>[] dependants)
        {
            obj.SetValue(ref field, value, notify, null, dependants);
        }

        public static void SetValue<T>(this PropertyChangedBase obj, ref T field, T value, Expression<Func<T>> notify, Action onChanged, params Expression<Func<object>>[] dependants)
        {
            if (EqualityComparer<T>.Default.Equals(field, value))
                return;

            field = value;

            obj.NotifyOfPropertyChange(notify);
            onChanged.Raise();
            dependants.Run(d => obj.NotifyOfPropertyChange(d));
        }
    }
}
